<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>01_数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型 + 引用类型
    //1.原始类型:number,string,boolean,undefined,null
    var a = 1;
    var b =3.14;
    console.log(a,typeof a,b,typeof b);//number
    var c = '你好';
    var d = "你好666";
    console.log(c,typeof c,d,typeof d);//string
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);//boolean
    var g;
    console.log(g,typeof g);//undefined 'undefined'
    var h = null;
    /*使用 typeof 操作符检查 null 的类型会返回 "object"，这是一个历史遗留问题。*/;
    console.log(h,typeof h);//null 'object'

    //引用类型:Object Array Function Number Boolean...
    let obj = {}
    console.log(obj,typeof obj);//{} 'object'
    let obj2 = {
        name:'张三',
        age:18
    };
    console.log(obj2,typeof obj2);
    console.log(obj2.name,obj2.age);
    //JS可以动态的往对象中新增属性
    obj2.like = '吃火锅';
    console.log(obj2);//{name: '张三', age: 18, like: '吃火锅'}
    obj2.play;
    console.log(obj2.play);//undefined

    //JS数组
    let arr = ['周一',3,4.6,true];
    console.log(arr);
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[99]);//访问数组不存在的下标会得到undefined

    //Boolean()用于将参数转为布尔类型
    //0,undefined,null,'',NaN这5个特殊值转为布尔是false
    console.log(Boolean(0));//false
    console.log(Boolean(undefined));//false
    console.log(Boolean(null));//false
    console.log(Boolean(''));//false
    console.log(Boolean(NaN));//false
    console.log(Boolean(' '));//true
    console.log(Boolean(1));//true
    console.log(Boolean('早上好'));//true

    //Number()用于将参数转为数值类型,如果得不到数字结果,值为NaN(Not a Number)
    console.log(Number(true),typeof Number(true));//1 'number'
    console.log(Number(false),typeof Number(false));//0 'number'
    console.log(Number(3),typeof Number(3));//3 'number'
    console.log(Number('3'),typeof Number('3'));//3 'number'
    console.log(Number('哈哈哈'),typeof Number('哈哈哈'));//NaN 'number'
</script>
</body>
</html>